<include file="public@header"/>
</head>
<body>
<div class="layui-fluid js-check-wrap">
    <form method="post" class="js-ajax-form" action="{:url('NavMenu/addPost')}">
        <div class="smart-widget widget-blue">
            <div class="layui-card">
                <div class="layui-card-header">{:lang('ADMIN_NAVMENU_ADD')}</div>
                <div class="layui-card-body">

                    <div class="layui-form-item">
                        <label class="layui-form-label">{:lang('TOP_PARENT')}:</label>
                        <div class="layui-input-block">
                            <select name="parent_id" class="layui-input form-control">
                                <option value="0">/</option>
                                {$nav_trees}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="form-required">*</span>{:lang('ADDRESS')}:</label>
                        <div class="layui-input-block">
                            <input type="radio" id="external-link-radio">&nbsp;
                            <input style="width:auto;display:inline-block;" type="text" class="layui-input" name="href" id="external-link-input">
                            &nbsp;&nbsp;
                            <input type="radio" id="select-href-radio">&nbsp;
                            <select style="width:auto;display:inline-block;" name="href" id="select-href" class="layui-input form-control">
                                <option value="{:base64_encode('home')}" data-name="首页">首页</option>
                                <foreach name="navs" item="vo">
                                    <optgroup label="{$vo.name}">
                                        {$vo.html}
                                    </optgroup>
                                </foreach>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="form-required">*</span>{:lang('MENU_NAME')}:</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" name="name" id="name-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">{:lang('OPEN_MODE')}:</label>
                        <div class="layui-input-block">
                            <select class="layui-input" name="target">
                                <option value="">{:lang('DEFAULT_MODE')}</option>
                                <option value="_blank">{:lang('NEW_WINDOW_OPEN')}</option>
                            </select>
                        </div>
                    </div>
                    <!-- <div class="form-group" >
                        <label class="layui-form-label">图标:</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" name="icon" value="">
                        </div>
                    </div> -->
                    <div class="layui-form-item">
                        <label class="layui-form-label">{:lang('PICTURE')}:</label>
                        <div class="layui-input-block">
                            <div class="upload-image">
                                <input type="hidden" name="thumb" id="thumbnail" value="">
                                <a href="javascript:uploadOneImage('{:lang('UPLOAD_IMAGE')}','#thumbnail');">
                                    <img src="__TMPL__/public/assets/images/default-thumbnail.png"
                                         id="thumbnail-preview"
                                         width="135" style="cursor: pointer"/>
                                </a>
                                <input type="button" class="layui-btn layui-btn-danger layui-btn-sm" onclick="$('#thumbnail-preview').attr('src','__TMPL__/public/assets/images/default-thumbnail.png');$('#thumbnail').val('');return false;
                                " value="{:lang('CANCEL_PICTURE')}">
                                <!-- <br>推荐尺寸 183px * 136px -->
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">{:lang('DISPLAY')}:</label>
                        <div class="layui-input-block">
                            <select name="status" class="layui-input">
                                <option value="1">{:lang('DISPLAY')}</option>
                                <option value="0">{:lang('HIDE')}</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <input type="hidden" name="nav_id" value="{$nav_id}"/>
                            <button type="submit" class="layui-btn layui-btn-normal js-ajax-submit">{:lang("SAVE")}</button>
                            <a class="layui-btn layui-btn-primary" href="{:url('NavMenu/index',['nav_id'=>$nav_id])}">{:lang("BACK")}</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>

</div>

<script>
    $(function () {
        checkChange(2);

        $("#select-href,#select-href-radio").click(function () {
            checkChange(2);
        });

        $("#select-href").change(function () {
            var $this = $(this);
            var label = $this.find("option[value='" + $this.val() + "']").data('name');
            $('#name-input').val(label);
        });

        $("#external-link-input,#external-link-radio").click(function () {
            checkChange(1);
        });

        function checkChange(i) {
            if (i == 1) {
                //自动输入url
                $('#external-link-input').attr('name', 'external_href');
                $('#select-href').removeAttr('name');
                $('#select-href-radio').prop('checked', false);
                $('#external-link-radio').prop('checked', true);
            } else {
                //选择链接url
                $('#select-href').attr('name', 'href');
                $('#external-link-input').removeAttr('name');
                $('#select-href-radio').prop('checked', true);
                $('#external-link-radio').prop('checked', false);
            }
        }
    });
</script>

<include file="public@footer"/>
